package me.ak.gui;

import java.util.ArrayList;
import java.util.List;

import me.ak.model.ScoreModel;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Rectangle;

public class BarRenderer {
	public static List<GuiBar> bars = new ArrayList<GuiBar>();
	
	public static GuiBar newBar(int x, int i) {
		GuiBar g = new GuiBar(x, i);
		bars.add(g);
		return g;
	}
	
	public static void updateScore(ScoreModel m) {
		bars = new ArrayList<GuiBar>();
		for (int i = 0; i < m.getScoreLength(); i++) {
			for (int ii = 0; ii < m.getBars().size(); ii++) {
				//BarModel bm = m.getBars().get(ii).get(i);
				GuiBar gb = new GuiBar(i, ii);
				bars.add(gb);
			}
		}
		System.out.println("Added " + bars.size() + " bars!");
	}
	
	public static enum BarlineType {
		DOUBLE, SINGLE, REPEAT
	}
	
	
	
	public static class GuiBar {
		public Rectangle bounds;
		public int offset;
		public BarlineType type = BarlineType.SINGLE;
		
		public GuiBar(int x, int i) {
			offset = i*50 + i*10;
			int barwidth = 200;
			int barheight = 40;
			bounds = new Rectangle(50 + (x*barwidth), offset, barwidth -1, barheight + 1);
		}
		
		
		public void draw(Graphics g) {
			g.pushTransform();
			g.scale(MainCanvas.z, MainCanvas.z);
			int yBarOffset = offset;
			g.setColor(Color.blue);
			g.fill(bounds);
			g.setColor(Color.white);
			for (int i = 0; i < 5; i++) {
				g.drawLine(bounds.getX(), yBarOffset, bounds.getX() + bounds.getWidth()-1, yBarOffset);
				yBarOffset += 10;
				//if (i == 3) {
					//g.fillOval(50, yBarOffset - 3, 10, 6);
					//g.drawLine(50 + 10, yBarOffset - 35, 60, yBarOffset);
				//}
			}
			if (type == BarlineType.DOUBLE) {
				g.drawLine((bounds.getX() + bounds.getWidth()) - ((3 - 1) + 3), bounds.getY(), (bounds.getX() + bounds.getWidth()) - ((3 - 1) + 3), bounds.getY() + bounds.getHeight());
				g.fillRect((bounds.getX() + bounds.getWidth()) - (3 - 1), bounds.getY(), 3, 40);
			}else {
				g.drawLine((bounds.getX() + bounds.getWidth())-1, bounds.getY(), (bounds.getX() + bounds.getWidth())-1, bounds.getY() + bounds.getHeight()-1);
			}
			
			
			
			
			g.popTransform();
		}
		
		
		
	}

}
